package util;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * Created with IntelliJ IDEA.
 * User: Oleg
 * Date: 06.12.13
 * Time: 2:52
 * To change this template use File | Settings | File Templates.
 */
public class Parser {

    public static StringBuffer parseFile(InputStream content){
        StringBuffer parseResult = new StringBuffer();
        try{
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(content));
            String line = "";
            StringTokenizer token = null;
            while ((line = bufferedReader.readLine()) != null){
                token = new StringTokenizer(line, ",");
                while(token.hasMoreTokens()){
                    parseResult.append(token.nextToken() + ",");
                }
                parseResult.append(";");
            }
        }catch(Exception e){
            System.out.println("Check your file.");
            e.printStackTrace();
            System.err.println("Parse Error: " + e.getMessage());
            System.out.println("The programm will close!");
        }
        return parseResult;
    }
}
